package com.ruoyi.project.manhua.mistake.controller;

import java.util.LinkedHashMap;
import java.util.List;
import com.ruoyi.project.manhua.climb.service.IMhClimbService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.manhua.mistake.domain.MhClimbMistake;
import com.ruoyi.project.manhua.mistake.service.IMhClimbMistakeService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 漫画爬虫错误Controller
 *
 * @author yuan
 * @date 2021-02-10
 */
@Controller
@RequestMapping("/manhua/mistake")
public class MhClimbMistakeController extends BaseController
{
    private String prefix = "manhua/mistake";

    @Autowired
    private IMhClimbMistakeService mhClimbMistakeService;

    @Autowired
    private IMhClimbService mhClimbService;

    @RequiresPermissions("manhua:mistake:view")
    @GetMapping()
    public String mistake(ModelMap map)
    {
        LinkedHashMap<Long, String> longStringLinkedHashMap = mhClimbService.mapMhNames();
        map.put("MhNameDataAll",longStringLinkedHashMap);
        return prefix + "/mistake";
    }

    /**
     * 查询漫画爬虫错误列表
     */
    @RequiresPermissions("manhua:mistake:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MhClimbMistake mhClimbMistake)
    {
        startPage();
        List<MhClimbMistake> list = mhClimbMistakeService.selectMhClimbMistakeList(mhClimbMistake);
        return getDataTable(list);
    }

    /**
     * 导出漫画爬虫错误列表
     */
    @RequiresPermissions("manhua:mistake:export")
    @Log(title = "漫画爬虫错误", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MhClimbMistake mhClimbMistake)
    {
        List<MhClimbMistake> list = mhClimbMistakeService.selectMhClimbMistakeList(mhClimbMistake);
        ExcelUtil<MhClimbMistake> util = new ExcelUtil<MhClimbMistake>(MhClimbMistake.class);
        return util.exportExcel(list, "mistake");
    }

    /**
     * 新增漫画爬虫错误
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存漫画爬虫错误
     */
    @RequiresPermissions("manhua:mistake:add")
    @Log(title = "漫画爬虫错误", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MhClimbMistake mhClimbMistake)
    {
        return toAjax(mhClimbMistakeService.insertMhClimbMistake(mhClimbMistake));
    }

    /**
     * 修改漫画爬虫错误
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        MhClimbMistake mhClimbMistake = mhClimbMistakeService.selectMhClimbMistakeById(id);
        mmap.put("mhClimbMistake", mhClimbMistake);
        return prefix + "/edit";
    }

    /**
     * 修改保存漫画爬虫错误
     */
    @RequiresPermissions("manhua:mistake:edit")
    @Log(title = "漫画爬虫错误", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MhClimbMistake mhClimbMistake)
    {
        return toAjax(mhClimbMistakeService.updateMhClimbMistake(mhClimbMistake));
    }

    /**
     * 删除漫画爬虫错误
     */
    @RequiresPermissions("manhua:mistake:remove")
    @Log(title = "漫画爬虫错误", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(mhClimbMistakeService.deleteMhClimbMistakeByIds(ids));
    }
}
